package com.web.servlet;

import com.web.entity.Teacher;
import com.web.service.TeacherService;
import com.web.serviceimpl.TeacherServiceImpl;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
 * 验证教师登录的servlet,并获取教师信息提交到teacherInfo.jsp
 * @author 12270
 */
@WebServlet("/lds")
public class TLoginServlet extends HttpServlet{

    TeacherService teacherService = new TeacherServiceImpl();
    
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        
        //1. 获取请求参数
        String Tid=req.getParameter("Tid");
        String Tpwd = req.getParameter("Tpwd");
        int zt ;
        
        //2. 执行业务逻辑
        Teacher teacher=teacherService.valedateLogin(Tid, Tpwd);
        HttpSession session = req.getSession();
        session.setAttribute("tea", teacher);
        zt=Integer.parseInt(teacher.getTstatus());
        System.out.println(zt);
        if(zt==1){
            resp.sendRedirect("teacherInfo.jsp");
        }else{
            resp.sendRedirect("TloginerrorPage.jsp");
        }
    }


    @Override
    public String getServletInfo() {
        return "success";
    }

    @Override
    public void destroy() {
    }
}
